package com.aispeech.asr.apis.ssc.data.domain;

import com.aispeech.asr.apis.ssc.data.form.SscForm;
import com.aispeech.asr.clib.utils.SplittedPcmData;
import lombok.Getter;
import lombok.Setter;

import java.io.File;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SscContext {
    @Getter
    private String sessionId;
    @Getter
    @Setter
    private Path pcmPath;

    @Getter
    private SscForm form;

    @Getter
    private File audioFile;

    private Map<String, Long> metrics;

    @Getter
    @Setter
    private List<SplittedPcmData.Offset> offsetList;

    @Getter
    @Setter
    private SscResult sscResult;

    public static SscContext of(String sessionId, SscForm form, File audioFile) {
        SscContext context = new SscContext();

        context.sessionId = sessionId;
        context.form = form;
        context.audioFile = audioFile;

        context.metrics = new HashMap<String, Long>() {{
            put("received", System.currentTimeMillis());
        }};

        return context;
    }

    public void addMetric(String metric) {
        if (form != null && metrics != null) {
            metrics.put(metric, System.currentTimeMillis());
        }
    }

    public Map<String, Long> getMetrics() {
        return metrics;
    }
}
